//
//  GYMyFirstSecondCell.m
//  GoodLuck
//
//  Created by 郭为勇 on 2018/2/25.
//  Copyright © 2018年 yunjiazhineng. All rights reserved.
//

#import "GYMyFirstSecondCell.h"
#import "GYOrderSelectedCollectionViewCell.h"

static NSString *orderListCellIdentifier = @"orderListCellIdentifier";

@interface GYMyFirstSecondCell ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

/** collectionView */
@property (nonatomic, strong) UICollectionView *collectionView;

/** <#description#> */
@property (nonatomic, strong) NSArray *images;

/** <#description#> */
@property (nonatomic, strong) NSArray *titles;

@end

@implementation GYMyFirstSecondCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        //初始化
        [self setupUI];
    }
    return self;
}

- (void)setUserInfo:(GYUserInfo *)userInfo {
    _userInfo = userInfo;
    
    [self.collectionView reloadData];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.collectionView.frame = self.contentView.bounds;
}
- (void)setupUI {
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    flowLayout.minimumLineSpacing = 0;
    flowLayout.minimumInteritemSpacing = 0;
    
    UICollectionView *collectionView =[[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.bounces = NO;
    [self.contentView addSubview:collectionView];
    
    self.collectionView = collectionView;

    //注册
    [collectionView registerNib:[UINib nibWithNibName:@"GYOrderSelectedCollectionViewCell" bundle:nil] forCellWithReuseIdentifier:orderListCellIdentifier];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 5;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    GYOrderSelectedCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:orderListCellIdentifier forIndexPath:indexPath];
    cell.orderImageView.image = [UIImage imageNamed:self.images[indexPath.item]];
    cell.orderTileLable.text = self.titles[indexPath.item];
//    NSLog(@"===%d",self.userInfo.order_nodev_count);
    switch (indexPath.item) {
        case 0:
        {
            cell.num = self.userInfo.order_nopay_count;
        }
            break;
            
        case 1:
        {
            cell.num = self.userInfo.order_nodev_count;
        }
            break;
            
        case 2:
        {
            cell.num = self.userInfo.order_noreceipt_count;
        }
            break;
            
        case 3:
        {
            cell.num = self.userInfo.order_noeval_count;
        }
            break;
            
        case 4:
        {
            cell.num = self.userInfo.returnCount;
        }
            break;
            
        default:
            break;
    }
    
    return cell;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(ScreenWidth/5, self.height);
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.allOrderBlock(indexPath.item+1);
}

#pragma mark -- 懒加载

- (NSArray *)images {
    if (!_images) {
        _images = @[@"mcc_01",@"mcc_02",@"mcc_03",@"mcc_04",@"mcc_05"];
    }
    
    return _images;
}

- (NSArray *)titles {
    if (!_titles) {
        _titles = @[@"待付款",@"待发货",@"待收货",@"待评价",@"退款/退货"];
    }
    
    return _titles;
}

@end
